package com.bj58.heatmap.util;

import java.text.DecimalFormat;

public class VelocityTools {
	public static String compRate2(Object num1,Object num2){
		if(num1==null && num2==null)
    		return "0%";
    	else if(num1==null)
    		return  "-100%";
    	else if(num2==null)
    		return  "100%";
		String strVal1=String.valueOf(num1);
		String strVal2=String.valueOf(num2);
		
		DecimalFormat df = new DecimalFormat("0.0");
		double num_one = Double.valueOf(strVal1);
		double num_two = Double.valueOf(strVal2);
		
		if(num_one==0 && num_two == 0){
			return  "0.0%";
		}else if(num_two == 0){
			return  "100.0%";
		}else if(num_one == 0){
			return  "-100.0%";
		}
		
		double sss = (num_one-num_two)/num_two;
		if(sss>0){
			return df.format(sss*100)+"%";
		}else if(sss <0){
			return df.format(sss*100)+"%";
		}else{
			return df.format(sss*100)+"%";
		}
		
	}
}
